package com.yvon.maple.service.msg.core.handler.pending;

import com.yvon.maple.service.msg.core.common.utils.GroupIdMappingUtils;
import com.yvon.maple.service.msg.core.handler.config.ThreadPoolConfig;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;

/**
 * @author : Yvon
 * @since : 2021-12-23
 */
@Component
public class TaskPendingHolder {

    private Integer coreSize = 3;
    private Integer maxSize = 3;
    private Integer queueSize = 100;
    private final Map<String , ExecutorService> taskPendingHolder = new HashMap<>(32);

    private static final List<String> groupIds = GroupIdMappingUtils.getAllGroupIds();


    @PostConstruct
    public void init() {
        for (String groupId : groupIds) {
            taskPendingHolder.put(groupId, ThreadPoolConfig.getThreadPool(coreSize, maxSize, queueSize));
        }
    }

    public ExecutorService getExecutor(String groupId) {
        return taskPendingHolder.get(groupId);
    }
}
